package com.douyu.ocean.serversCheck;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RunShellFile {
	private static Logger log = LoggerFactory.getLogger(RunShellFile.class);
	public static List<String> runFile(String file, String[] args){
		
		
		List<String> strList = new ArrayList<String>();
		
		StringBuffer sb = new StringBuffer();
		sb.append("/bin/bash ");
		sb.append(file+" ");
		for(int i=0;i<args.length; i++){
			sb.append(args[i]);
			sb.append(" ");
		}
		log.info("check region with command : "+sb.toString());
		
		
		try {
			Process process = Runtime.getRuntime().exec(sb.toString());
			process.waitFor();
			BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));

			String line = "";
			while((line = input.readLine())!= null){
				strList.add(line);
			}
			
			input.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return strList;
	}
	
	public static void main(String[] args){
		String [] a = new String[1];
		a[0] = "172.16.253.128";
		RunShellFile.runFile("check.sh", a);
	}
}
